package com.bawei.rk_01

import android.graphics.Color
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.base.utils.mvvm.BaseViewActivity
import com.bawei.rk_01.databinding.ActivityCouponsBinding
import com.bawei.rk_01.fm.CouponsFragment1
import com.bawei.rk_01.fm.CouponsFragment2
import com.bawei.rk_01.fmadapter.MyFmAdapter
import com.bawei.rk_01.fmadapter.MyTab
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener

@Route(path = "/app/CouponsActivity")

class CouponsActivity : BaseViewActivity<ActivityCouponsBinding>() {

    val list = ArrayList<Fragment>()
    lateinit var myFmAdapter: MyFmAdapter

    override fun getLayout(): Int {
        return R.layout.activity_coupons
    }

    override fun initView() {

        list.add(CouponsFragment1())
        list.add(CouponsFragment2())
        myFmAdapter = MyFmAdapter(this,list)
        binding.v2.adapter = myFmAdapter

        val arrayList = ArrayList<CustomTabEntity>()
        arrayList.add(MyTab("未使用",0,0))
        arrayList.add(MyTab("已使用/过期",0,0))
        binding.tab.setTabData(arrayList)
        binding.tab.indicatorHeight = 1f
        binding.tab.indicatorWidth = 100f
        binding.tab.indicatorColor = Color.GREEN

        binding.tab.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                binding.v2.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }
        })

        binding.v2.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.tab.currentTab = position
            }
        })

    }

    override fun initData() {

    }

}